home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / 80X86 / DOS32V33.ZIP / EXAMPLES / EG2.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-08-25  |  2.1 KB  |  99 lines

  1. ;***************************************************************************
  2. ; EG2.ASM
  3. ;             This program will allocated a memory block and fill it.
  4. ;
  5. ; DOS32 assembly language example program
  6. ;***************************************************************************
  7.  
  8. .386
  9. .model flat
  10. .stack 200h
  11. .code
  12.  
  13.  
  14.  
  15. fill_message   db ' (hex) bytes allocated.  Now Filling block ...  ',10,13,36
  16.  
  17.  
  18.  
  19. TheStart:                                ; first intruction executed here
  20.  
  21. ;
  22. ; Use the Memory Allocation Service and attept to allocate 4GB
  23. ;
  24.         mov     edx,-1
  25.         mov     ax,0EE42h
  26.         int     31h                            ; Returns EAX with actual size
  27.         cmp     eax,0
  28.         jnz enfmem
  29.            mov  ah,4ch                         ; Terminate if size is 0
  30.            int  21h
  31. enfmem:
  32.  
  33. ; EDX now equals a near pointer of the memory block and
  34. ; EAX equals the number bytes that were allocated
  35.  
  36.  
  37.  
  38.  
  39. ;
  40. ; Print the amount of memory that was actually allocated
  41. ;
  42.         push    eax
  43.         push    edx                             ; Save EDX.
  44.         call    print_hex                       ; Print EAX then
  45.         mov     edx,offset fill_message         ; print a message
  46.         mov     ah,9
  47.         int     21h
  48.         pop     edx                             ; restore EDX
  49.         pop     eax
  50.  
  51.  
  52. ;
  53. ; Fill the allocated memory block
  54. ;
  55.         mov     edi,edx                         ; EDX = offset
  56.         mov     ecx,eax                         ; EAX = count
  57.         shr     ecx,2
  58.         rep     stosd
  59.  
  60. ;
  61. ; Termiate the program
  62. ;
  63.         mov   ax,4c00h
  64.         int   21h
  65.  
  66.  
  67.  
  68.  
  69.  
  70. ;
  71. ; A procedure that will print EAX on the screen
  72. ;
  73. print_hex   PROC
  74.         pushad
  75.         mov     digit,eax
  76.         mov     ecx,8
  77. L11:
  78.         rol     digit,4
  79.         mov     al,byte ptr digit
  80.         and     al,0fh
  81.         cmp     al,10
  82.         jb j8
  83.         add      al,'A'-'0'-10
  84. j8:     add     al,'0'
  85.         mov     dl,al
  86.         mov     ah,02h
  87.         int     21h
  88.         loop L11
  89.         popad
  90.         ret
  91.  
  92. digit   dd      0
  93.  
  94. print_hex ENDP
  95.  
  96.  
  97.  
  98. END TheStart
  99.